
window.onload = function(){
	$('body').on('input','#tel',function(){
			var tel = $(this).val();
			if(tel.length == 11){
				var reg=/^1[3,5,7,8,9]\d{9}$/;
				if(tel == "" || !reg.test(tel)){
					layer.msg('请输入正确的手机号');
					return false;
				}
			}
	});
	$('body').on('click','#sendToTel',function(){
		$('#getcode').val('');
		var btn = $(this);
		var tel = $('#tel').val();
		var reg=/^1[3,5,7,8,9]\d{9}$/;
		var time = 60;
		if(tel == "" || !reg.test(tel)){
			layer.msg('请输入正确的手机号');
			return false;
		}
		app.ajax(
			'/Index/Index/send',
			{
				mobile : tel
			},function(res){
				 $("#sendToTel").text("59s");
				 var time = 60;
               hander = setInterval(function () {
                    if (time <= 0) {
                        canSend = true;
                        clearInterval(hander);
                        btn.text("59s");
                        btn.removeAttr("disabled");
                    }
                    else {
                        canSend = false;
                        time--;
                        btn.attr({ "disabled": "disabled" });
                        btn.text( time + "s");
                }
			},1000);
		});
	});
	
	$('body').on('click','.getMoney',function(){
		var tel = $('#tel').val();
		var code = $('#valid').val();
		var reg=/^1[3,5,7,8,9]\d{9}$/;
		if(tel == "" || !reg.test(tel)){
			layer.msg('请输入正确的手机号');
			return false;
		}
		app.ajax(
			'/Member/Index/receive_red',
			{
				mobile : tel,
				code   :code
			},function(res){
				if(res.code==200){
					layer.msg('领取成功');
					setTimeout(function(){
						app.open('regiRed.gotScucces.html','gotScucces',{tel:tel},window.location.href,document.body.scrollTop);
					},2000);
				}else if(res.code == 300){
					app.open('regiRed.already.html','gotAlready',{},window.location.href,document.body.scrollTop);
				}
			}
		)
	});

}
